package com.googlecode.excavator.pref;

public class PerfRunner implements Runnable {

	private Perf perf;
	private boolean isDead = false;
	private PerfReporter reporter;
	
	
	
	public PerfRunner(Perf perf, PerfReporter reporter) {
		this.perf = perf;
		this.reporter = reporter;
	}


	@Override
	public void run() {
		
		while( !isDead ) {
			final long start = System.currentTimeMillis();
			boolean successed = true;
			try {
				perf.perf();
			}catch(Throwable t) {
				successed = false;
			} finally {
				final long cost = System.currentTimeMillis() - start;
				reporter.report(cost, successed);
			}//try
		}
		
	}
	
	public void kill() {
		isDead = true;
	}

}
